<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>结构选择器</title>
  <style>
    *{
      margin: 0;
      padding:0;
    }
    ul{
      padding-left: 10px;
      width: 800px;
      height: 160px;
      margin: 20px auto;
      background-color: pink;
    }
    li{
      float: left;
      list-style: none;
      min-width: 50px;
      height: 50px;
      background-color: #005971;
      margin: 10px;
      font-size: 12px;
      color: white;
    }

    .tips{
      position: absolute;
      top: 0;
      right: 50%; 
      margin-right: 420px;
      padding-left: 0;
      width: 70px;
      height: 140px;
      color:  white;
      font-size: 12px;
    }
    .checked{
      background-color: #218300;
    }
    .default{
      background-color: #005971;
    }

    .demo1 li:first-child{
      background-color: #218300;
    
    }
    .demo1 li:last-child{
      background-color: #218300;
    }
    .demo1 li:nth-child(3){
      background-color: #218300;
    }

    .demo2 li:nth-child(2n+1){
      background-color: #218300;
    }

    .demo3 li:nth-child(2n){
      background-color: #218300;
    }
    .demo4 li:nth-child(-n+3){
      background-color: #218300;
    }
    .demo5 li:nth-last-child(-n+4){
      background-color: #218300;
    }
    .demo6 li:nth-child(3n+2){
      background-color: #218300;
    }

    .demo7 li:nth-child(-n+8):nth-child(n+4){
      background-color: #218300;
    }

    .demo11 li:first-of-type,
    .demo11 li:last-of-type{
      background-color: #218300;
    }
    .demo22 li:nth-of-type(-n+3){
      background-color: #218300;
    }
    .demo33 li:nth-of-type(odd){
      background-color: #218300;
    }
    .demo44 li:nth-of-type(even){
      background-color: #218300;
    }

  </style>
</head>

<body>
  <ul class="tips">
    <li class="checked">选中颜色</li>
    <li class="default">默认颜色</li>
  </ul>
  <ul>
    <li>n 从0(整数)开始时依次代入表达式得到结果</li>
    <li>nth-child 从左往右数 (元素坐标是从1开始)</li>
    <li>nth-last-child 从右往左数 (元素坐标是从1开始)</li>
    <li>nth-child 和 nth-of-type 区别</li>
    <li>child是指【子代】元素 先结构选择器后看标签是否匹配 of-type从【标签选择器】选中挑选</li>
  </ul>
  <ul class="demo1">
    <li class="lable">li:first-child</li>
    <li class="lable"></li>
    <li class="lable">li:nth-child(3)</li>
    <li class="lable"></li>
    <li></li>
    <li></li>
    <li>li:last-child</li>
   
  </ul>
  <ul class="demo2"> 
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1"></li>
    <li class="lable_1"></li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_3"></li>
    <li class="lable_3">li:nth-child(2n+1)</li>
    奇数
  </ul>
  <ul class="demo3">
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1"></li>
    <li class="lable_1"></li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_3">li:nth-child(2n)</li>
    <li class="lable_3"></li>
    偶数
  </ul>
  <ul class="demo4">
    <li class="lable">li:nth-child(-n+3)</li>
    <li class="lable"></li>
    <li class="lable_1_"></li>
    <li class="lable_1_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
    前3
  </ul>
  <ul class="demo5">
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1_"></li>
    <li class="lable_1_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
    后4
  </ul>
  <ul class="demo6">
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1_">li:nth-child(3n+2)</li>
    <li class="lable_1_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
    第2个起 每隔3个
  </ul>
  <ul class="demo7">
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1_"></li>
    <li class="lable_1_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_3">li:nth-child(-n+8):nth-child(n+4)</li>
    <li class="lable_3"></li>
    第4 到 第8
  </ul>

  <ul class="demo11">
    <p>li:first-of-type</p>
    <li class="lable">前面有P标签</li>
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable"></li>
    <li></li>
    <li></li>
    <p>li:last-of-type</p>
    <li></li>
  </ul>
  <ul class="demo22"> 
    
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1"></li>
    <p>li:nth-of-type(-n+3)</p>
    <li class="lable_1">前面有p标签</li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_2"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
  </ul>
  <ul class="demo33">
    <li class="lable"></li>
    <li class="lable"></li>
    <li class="lable_1"></li>
    <li class="lable_1"></li>
    <li class="lable_2"></li>
    <p>li:nth-of-type(odd)</p>
    <li class="lable_2">前面有p标签</li>
    <li class="lable_2"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
    
  </ul>
  <ul class="demo44">
    <li class="lable"></li>
    <li class="lable"></li>
    <p>li:nth-of-type(even)</p>
    <li class="lable_1_">前面有p标签</li>
    <li class="lable_1_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_2_"></li>
    <li class="lable_3"></li>
    <li class="lable_3"></li>
  </ul>
</body>

</html>